<template>

    <a-card :bordered="false">
      <a-tabs>
        <a-tab-pane tab="劳动者信息" key="WorkForm" forceRender>
          <workForm ref="WorkForm"></workForm>
        </a-tab-pane>

        <a-tab-pane tab="关系信息" key="RelationForm" forceRender>
          <relationForm ref="RelationForm"></relationForm>
        </a-tab-pane>

        <a-tab-pane tab="就职信息" key="OfficeFrom" forceRender>
          <officeFrom ref="OfficeFrom"></officeFrom>
        </a-tab-pane>

      </a-tabs>
    </a-card>

</template>

<script>
  import WorkForm from '@views/crm/empwork/modules/form/WorkForm'
  import RelationForm from '@views/crm/empwork/modules/form/RelationForm'
  import OfficeFrom from '@views/crm/empwork/modules/form/OfficeForm'

  import { httpAction, getAction } from '@/api/manage'

  export default {
    name: 'EmpWorkForm',
    components: {
      WorkForm,RelationForm,OfficeFrom
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      row:["row"]
    },
    data () {
      return {
        model:{
          isConversion:0
        },
        url: {
          add: "/empWork/add",
          edit: "/empWork/edit",
          queryById: "/empWork/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    methods: {
      submitForm () {
        console.log('来提交了')
        // 触发表单验证
        this.$refs.WorkForm.validates((data)=>{
          console.log(data)
          if (data) {
            /*Object.assign(this.model,this.$refs.WorkForm.model);
            console.log(this.$refs.WorkForm.model);
            Object.assign(this.model,this.$refs.RelationForm.model);
            Object.assign(this.model,this.$refs.OfficeFrom.model);*/
            this.model.empWorkVo = this.$refs.WorkForm.model;
            this.model.empWorkVo.isConversion = this.model.isConversion;

            this.model.empOfficeVO = this.$refs.OfficeFrom.model;
            this.model.empRelationVO = this.$refs.RelationForm.model;
            console.log(this.model);
            const that = this;
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        });

      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.WorkForm.edit(record);
        this.$refs.RelationForm.edit(record);
        this.$refs.OfficeFrom.edit(record);
      },
      details(record){
        this.$refs.WorkForm.edit(record);
        this.$refs.RelationForm.edit(record);
        this.$refs.OfficeFrom.edit(record);

        this.$refs.WorkForm.disabled = true;
        this.$refs.RelationForm.disabled = true;
        this.$refs.OfficeFrom.disabled = true;
      }
    },
  }
</script>